import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.DataOutputStream;

public class ReadAndSortNumbers {
    public static void main(String[] args) {
        System.out.println("202301110038 + 张洪健");
        String inputFileName = "out.dat";
        String outputFileName = "sort.dat";
        int numberOfNumbers = 100;

        int[] numbers = new int[numberOfNumbers];

        try (DataInputStream dis = new DataInputStream(new FileInputStream(inputFileName))) {
            for (int i = 0; i < numberOfNumbers; i++) {
                numbers[i] = dis.readInt();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


        Arrays.sort(numbers);


        System.out.println("Sorted numbers:");
        for (int number : numbers) {
            System.out.println(number);
        }


        try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(outputFileName))) {
            for (int number : numbers) {
                dos.writeInt(number);
            }
            System.out.println("Sorted numbers have been written to " + outputFileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}